window.onload = function () {
    //发送Ajax请求
    $.ajax({
        type: "post",
        url: "/js/compent/Tea.js",
        data: null,
        dataType: "json",
        success: function (data) {
            let dataObjList = JSON.parse(data);
            document.getElementById("goodshow").innerHTML = "";
            let str = "";
            for (let i = 0; i < dataObjList.length; i++) {
                str += `
                <div class="good">
                    <div class="good-img">
                        <img src="../img/${dataObjList[i].teaImg}" alt="">
                    </div>
                    <div class="good-title">
                        <div>
                            <a href="" class="teaname">${dataObjList[i].teaName}</a>
                        </div>
                        <div class="underline2"></div>
                        <div class="underline3"></div>
                    </div>
                    <div class="good-price">
                        <span class="teaprice">￥${dataObjList[i].teaPrice}</span>
                    </div>
                    <div class="good-href">
                    <span onclick="fun1('${dataObjList[i].teaName}')">→</span>
                    </div>
                </div>`
            }
            document.getElementById("goodshow").innerHTML = str;
        }
    })
}

function fun(index) {
    let obj = {
        index: index
    }
    $.ajax({
        type: "post",
        url: "/js/fun",
        data: JSON.stringify(obj),
        dataType: "json",
        success: function (data) {
            let dataObj = data;

            let fu = document.getElementById("goodshow");
            fu.innerHTML = "";
            let str = "";
            for (let i = 0; i < dataObj.length; i++) {
                str += `
                <div class="good">
                    <div class="good-img">
                        <img src="../img/${dataObj[i].teaImg}" alt="">
                    </div>
                    <div class="good-title">
                        <div>
                            <a href="" class="teaname">${dataObj[i].teaName}</a>
                        </div>
                        <div class="underline2"></div>
                        <div class="underline3"></div>
                    </div>
                    <div class="good-price">
                        <span class="teaprice">￥${dataObj[i].teaPrice}</span>
                    </div>
                    <div class="good-href">
                        <span onclick="fun1('${dataObj[i].teaName}')">→</span>
                    </div>
                </div> `
            }
            fu.innerHTML = str;
        }
    })
}

function fun1(name) {
    let obj={
        teaName:name
    }
    $.ajax({
        type: "post",
        url: "/js/fun1",
        data: JSON.stringify(obj),
        dataType: "json",
        success:function(data){
            if(data){
                location.href = "../view/xiangqing.html";
            }else{
                alert("跳转失败");
            }
        }
    })
    
}

